﻿package com.wandian.view.mediator.shop
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.util.RadioManage;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.GiveGiftPlayer;
	import com.wandian.view.components.ui.MaskTipPanel;
	import com.wandian.view.components.ui.PropGiftInfo;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

    public class ShopPropMediator extends Mediator
    {
        private var _tabBar:CLZTabBar;
        private var _onPlayerVo:PlayerVo;
        private var _nType:int = 0;
        private var _arrShowProp:Array;
        private var _recordPropNum:int;
        public static const NAME:String = "ShopPropMediator";

        public function ShopPropMediator(param1:MovieClip, param2:PlayerVo, param3:int)
        {
            this._arrShowProp = [];
            this._onPlayerVo = param2;
            this._nType = param3;
            super(NAME, param1);
            return;
        }

        override public function onRegister() : void
        {
            switch(this._nType)
            {
                case GameData.SHOP_HOTPROP_TYPE:
                {
                    this.sendNotification(CLZNoticeName.SHOP_HOT_PROP_LIST_REQ);
                    break;
                }
                case GameData.SHOP_INTERACTIVEPROP_TYPE:
                {
                    this.sendNotification(CLZNoticeName.SHOP_INTERACTIVE_PROP_LIST_REQ);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function showPropList(arrShop:Array) : void
        {
			if (arrShop == null||arrShop.length == 0)
			{
				return;
			} 
            var _mcGift:MovieClip = null;         
            var mcListScroll:CLZLlistScrollPanel = new CLZLlistScrollPanel(6, 102, 151, 20, 20, 446, 734);
            this.mcProp.addChild(mcListScroll);
            mcListScroll.x = 15;
            mcListScroll.y = 10;
            var total:* = arrShop.length;
            var index:int = 0;
            while (index < total)
            {
                
                _mcGift = GameData.getMovieClip("GiftMc");
                mcListScroll.setMc(_mcGift, index, total);
                this._arrShowProp[index] = new PropGiftInfo(_mcGift, arrShop[index], index);
                this._arrShowProp[index].addEventListener(Event.CHANGE, this.changePropHandler);
                index = index + 1;
            }
            return;
        }

        private function changePropHandler(event:Event) : void
        {
            if (this._recordPropNum != event.target.num)
            {
                this._arrShowProp[this._recordPropNum].recoveryState();
            }
            this._recordPropNum = event.target.num;
            this._arrShowProp[this._recordPropNum].clickThis();
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.SHOP_HOT_PROP_LIST_RES, CLZNoticeName.SHOP_INTERACTIVE_PROP_LIST_RES];
        }

        override public function handleNotification(param1:INotification) : void
        {
            var _loc_2:* = param1.getBody() as Array;
            switch(param1.getName())
            {
                case CLZNoticeName.SHOP_HOT_PROP_LIST_RES:
                {
                    this.showPropList(_loc_2);
                    break;
                }
                case CLZNoticeName.SHOP_INTERACTIVE_PROP_LIST_RES:
                {
                    this.showPropList(_loc_2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function get mcProp() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
